//时间格式化
export const formatterDate = (date, format = 'yyyy-MM-dd HH:mm:ss') => {
  let nowDate = {
    yyyy: date.getFullYear(), // 年
    MM: date.getMonth() + 1, // 月份
    dd: date.getDate(), //日
    hh: date.getHours(),
    mm: date.getMinutes(),
    ss: date.getSeconds()
  }
  if (/(y+)/.test(format)) {
    format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  for (var k in nowDate) {
    if (new RegExp('(' + k + ')').test(format)) {
      format = format.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ? nowDate[k] : ('00' + nowDate[k]).substr(('' + nowDate[k]).length)
      )
    }
  }
  return format
}

// 根据当前日期生成前n天数据
export const mockDays = (num: number) => {
  const dateList = [...Array(num).keys()].map((days: number) => {
    const t = new Date(Date.now() - 86400000 * days)
    const str = `${t.getFullYear()}年${t.getMonth() + 1}月${t.getDate()}日`
    return str
  })
  return dateList
}
// 根据当前日期生成前n月数据
export const mockMonths = (num: number) => {
  const dateList = [...Array(num).keys()].map((index: number) => {
    const t = new Date()
    t.setMonth(t.getMonth() - index)
    const year = t.getFullYear()
    const monthStr = (t.getMonth() + 1).toString().padStart(2, '0')
    return `${year}年${monthStr}月`
  })
  return dateList
}
